package com.bingwang.sourcelearn.beans;

import com.bingwang.sourcelearn.beans.config.JavaConfig;
import com.bingwang.sourcelearn.beans.domain.User;
import com.bingwang.sourcelearn.utils.ContextUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author WangBing
 * @date 2023/11/4 12:09
 */
public class TestMain {

    public static void main(String[] args) {
//        User user = getUserFromJavaConfig();
        User user = getUserFromXmlConfig();
        System.out.println(user);
    }

    private static User getUserFromXmlConfig() {
        // 创建bean容器
        final ApplicationContext acx = ContextUtil.getContext("beans.xml");
        return (User) acx.getBean("userInXml");
    }

    private static User getUserFromJavaConfig() {
        final ApplicationContext acx = ContextUtil.getContext(JavaConfig.class);
        return acx.getBean(User.class);
    }
}
